﻿using System;
using System.Collections.Generic;
using EZCRS.HCMS.Entity;
using EZCRS.HCMS.SqlClient;
using EZCRS.HCMS.Bll;
using System.Text;

namespace EZCRS.HCMS.Bll.baseinfo
{
    public class ZoneBaseInfo
    {
        #region 生成地区js数据 /common/zone.js
        /// <summary>
        /// 生成地区js数据 /common/zone.js
        /// </summary>
        public void createzonejs(string filename)
        {
            List<HCRS_Province> _province = new sql_hcrs_province().getallprovince("",0);
            List<HCRS_City> _city = new sql_hcrs_city().getallcity(0);
            List<HCRS_District> _district = new sql_hcrs_district().getalldistrict(0);
            List<HCRS_Commercial> _commercial = new sql_hcrs_commercial().getallcommercial(0);

            StringBuilder zonejs = new StringBuilder();

            zonejs.Append("var Zpro = new Array();var Zcity = new Array();var Zdist = new Array();var Zcomm=new Array();");
            int i = 0;
            foreach (HCRS_Province _p in _province)
            {
                zonejs.Append("Zpro["+i.ToString()+"] = \""+_p.Id.ToString()+","+_p.Name+"\";");
                i++;
            }
            
            i = 0;
            foreach (HCRS_City _c in _city)
            {
                zonejs.Append("Zcity["+i.ToString()+"] = \""+_c.ProvinceID.ToString()+","+_c.Id.ToString()+","+_c.Name+"\";");
                i++;
            }

            i = 0;
            foreach (HCRS_District _d in _district)
            {
                zonejs.Append("Zdist["+i.ToString()+"] = \""+_d.CityID.ToString()+","+_d.Id.ToString()+","+_d.Name+"\";");
                i++;
            }

            i = 0;
            foreach (HCRS_Commercial _comm in _commercial)
            {
                zonejs.Append("Zcomm[" + i.ToString() + "] = \"" + _comm.CityID.ToString() + "," + _comm.Id.ToString() + "," + _comm.Name + "\";");
                i++;
            }

            CFun.saveFile(zonejs, filename, "9");
        }
        #endregion

        #region 国家信息维护
        public List<HCRS_Country> getallcountry(int languagetype)
        {
            return new sql_hcrs_country().getcountry(languagetype);
        }
        public bool deletecountry(int id)
        {
            return new sql_hcrs_country().deletecountry(id);
        }
        public bool insertorupdatecountry(HCRS_Country _country)
        {
            return new sql_hcrs_country().insertorupdate(_country);
        }
        #endregion

        #region 省份信息维护
        public List<HCRS_Province> getprovince(string countryid,int languagetype)
        {
            return new sql_hcrs_province().getallprovince(countryid,languagetype);
        }
        public bool deleteprovince(int id)
        {
            return new sql_hcrs_province().delprovince(id);
        }
        public bool insertorupdateprovince(HCRS_Province _province)
        {
            return new sql_hcrs_province().insertorupdate(_province);
        }
        #endregion

        #region 城市信息维护
        public List<HCRS_City> getcity(int id,int languagetype)
        {
            return new sql_hcrs_city().getallcity(id);
        }
        public bool deletecity(int id)
        {
            return new sql_hcrs_city().delcity(id);
        }
        public bool insertorupdatecity(HCRS_City _city)
        {
            return new sql_hcrs_city().insertorupdate(_city);
        }
        #endregion

        #region 区信息维护
        public List<HCRS_District> getdistrict(int id,int lang)
        {
            return new sql_hcrs_district().getalldistrict(id);
        }
        public bool deletedistrict(int id)
        {
            return new sql_hcrs_district().deldistrict(id);
        }
        public bool insertorupdatedistrict(HCRS_District _district)
        {
            return new sql_hcrs_district().insertorupdate(_district);
        }
        #endregion

        #region 商业区信息维护
        public List<HCRS_Commercial> getcommercial(int id,int languagetype)
        {
            return new sql_hcrs_commercial().getallcommercial(id);
        }
        public bool deletecommercial(int id)
        {
            return new sql_hcrs_commercial().delcommercial(id);
        }
        public bool insertorupdatecommercial(HCRS_Commercial _commercial)
        {
            return new sql_hcrs_commercial().insertorupdate(_commercial);
        }
        #endregion
    }
}
